class MyNode {
  constructor(data) {
    this.data = data;
    this.next = null;
  }
}

function isCycle(head) {
  let p1 = head;
  let p2 = head;
  while(p2!=null && p2.next != null) {
    p1 = p1.next;
    p2 = p2.next.next;
    if (p1 == p2) {
      return true;
    }
  }
  return false;
}
let node1 = new MyNode(5);
let node2 = new MyNode(3);
let node3 = new MyNode(7);
let node4 = new MyNode(2);
let node5 = new MyNode(6);
node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5;
node5.next = node2;
console.log(isCycle(node1));
        
